package ntut.andengine.physics;

import ntut.andengine.events.UpdateCommand;
import ntut.andengine.game.GameLevel;

import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.entity.shape.Shape;
import org.anddev.andengine.extension.physics.box2d.PhysicsFactory;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.FixtureDef;

public class Frame extends PhysicalComponent {
	
	Shape ground;
	Shape roof;
	Shape left;
	Shape right;
	int mSide;
	
	public Frame(GameLevel level, int side) {
		super(level);
		mSide = side;
		
		ground = new Rectangle(0, side - 2, side, 2);
		roof = new Rectangle(0, 0, side, 2);
		left = new Rectangle(0, 0, 2, side);
		right = new Rectangle(side - 2, 0, 2, side);
		
		final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(1, 0, 0);//(0, 0, 0, false, CATEGORYBIT_WHITE, MASKBITS_WHITE, (short)0);
		PhysicsFactory.createBoxBody(level.getPhysicsWorld(), ground, BodyType.KinematicBody, wallFixtureDef);
		PhysicsFactory.createBoxBody(level.getPhysicsWorld(), roof, BodyType.KinematicBody, wallFixtureDef);
		PhysicsFactory.createBoxBody(level.getPhysicsWorld(), left, BodyType.KinematicBody, wallFixtureDef);
		PhysicsFactory.createBoxBody(level.getPhysicsWorld(), right, BodyType.KinematicBody, wallFixtureDef);

		level.getScene().attachChild(ground);
		level.getScene().attachChild(roof);
		level.getScene().attachChild(left);
		level.getScene().attachChild(right);
		
		
		level.addUpdateCommand(new UpdateCommand(){

			@Override
			public void updateCommand(float pSecondsElapsed) {
				
				
			}
			
		});
	}
	
	public void setPosition(Vector2 center){
		
		ground.setPosition(center.x, center.y+mSide-2);
		roof.setPosition(center.x, center.y-mSide);
		left.setPosition(center.x-mSide, center.y);
		right.setPosition(center.x+mSide-2, center.y);
	}
	
//	public void setColor(ComponentColor color){
//		
//		Filter filter = new Filter();
//		
//		switch(color){
//		case White:
//			if(mSprite != null) mSprite.setColor(1, 1, 1);
//			ground.get
//			
//			filter.categoryBits = GameSceneLevel.CATEGORYBIT_WHITE;
//			filter.maskBits = GameSceneLevel.MASKBITS_WHITE;			
//			for (Fixture f:mBody.getFixtureList())
//			{
//				f.setFilterData(filter);
//			}
//			break;
//		case Red:
//			mSprite.setColor(1, 0, 0);
//			filter.categoryBits = GameSceneLevel.CATEGORYBIT_RED;
//			filter.maskBits = GameSceneLevel.MASKBITS_RED;			
//			for (Fixture f:mBody.getFixtureList())
//			{
//				f.setFilterData(filter);
//			}
//			break;
//		case Blue:
//			mSprite.setColor(0, 0, 1);	
//			filter.categoryBits = GameSceneLevel.CATEGORYBIT_BLUE;
//			filter.maskBits = GameSceneLevel.MASKBITS_BLUE;			
//			for (Fixture f:mBody.getFixtureList())
//			{
//				f.setFilterData(filter);
//			}
//			break;
//		}
//	}
}
